namespace Probel.Client.Commands
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    using Probel.Client.StatLoggerReference;
    using Probel.Statistics.Helpers;

    [Command("insert", "ins", "Insert debug data into the database")]
    public class InsertCommand : ICommand
    {
        #region Fields

        private readonly string[] Applications = new string[] { "nDoctor", "nDoctor Light" };
        private readonly Random Random = new Random();
        private readonly string[] Response = new string[] { "y", "yes" };

        #endregion Fields

        #region Methods

        public void Execute(dynamic context)
        {
            var os = SystemInfo.Load();
            var proxy = context.ProxyLogger as IStatLogger;
            var input = context.Input as Input;

            var result = input.Read("Do you want to add dummy data into the database? (Y(es)/N(o)): ");
            if (Response.Contains(result.ToLower()))
            {

                Console.Write("Inserting data ... ");
                var left = Console.CursorLeft;
                var top = Console.CursorTop;

                for (int i = 0; i < 250; i++)
                {
                    var text = Guid.NewGuid().ToString();
                    proxy.Register(text, os.Version, GetApplicationName());
                    Console.SetCursorPosition(left, top);
                    Console.WriteLine("{0,-3}%", (int)((100f / 250f) * i + 1));
                }
            }
            else { Console.WriteLine("Cancelled"); }
        }

        private string GetApplicationName()
        {
            return Applications[Random.Next(0, 2)];
        }

        #endregion Methods
    }
}